package com.quanyan.stadium.component.asyn;

import com.quanyan.common.mail.EmailUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 *  异步调用的service类
 *
 *
 */
@Component("stadiumAsyncService")
public class StadiumAsyncService{

    private static Logger logger = LoggerFactory.getLogger(StadiumAsyncService.class);


    /**
     *  运动场邮件异常
     *
     * */
    private final static String EMAIL_SUBJECT = ";<运动场模块>出现异常,请求路径:";
    private final static String API_EMAILS = "lei.w@quncaotech.com;dongsheng.lin@quncaotech.com;yiqiang.zou@quncaotech.com";
    private final static String WEB_EMAILS = "lei.w@quncaotech.com;dongsheng.lin@quncaotech.com;yiqiang.zou@quncaotech.com";
    
    @Async
    public void sendMail(HttpServletRequest request, String errorMsg) {
        String uri = request.getRequestURI(), emails;
        if (uri.startsWith("/admin/api/stadium/")){
            emails = WEB_EMAILS;
        }else if ( uri.startsWith("/api/stadium/gameSignUp")
                || uri.startsWith("//api/stadium/gameSignUp")
                || uri.startsWith("/api/stadium/radarchart")
                ) {
            emails = "dongsheng.lin@quncaotech.com";
        }else if ( uri.startsWith("/api/stadium/personalGameEvent/selectPersonalGameEventDetail")
                || uri.startsWith("/api/stadium/personalGameEvent/getRecordResultMessage")
                || uri.startsWith("/api/stadium/personalGameEvent/recordResultForPersonalAgainst")
                || uri.startsWith("/api/stadium/userCenter/getGameEventList")
                || uri.startsWith("/api/stadium/sportCard")
                || uri.startsWith("/api/stadium/gradeIntegral")
                || uri.startsWith("/api/stadium/gameEvent/gameCategoryAndSystemForLive")
                || uri.startsWith("/api/stadium/gameEvent/createArrangeLiveGameEvent")
                || uri.startsWith("/api/stadium/gameEventOrder")
                ) {
            emails = "dongsheng.lin@quncaotech.com";
        }else if (  uri.startsWith("/api/stadium/pkEvent")
                ||  uri.startsWith("/api/stadium/userCenter")
                || uri.startsWith("/api/stadium/gameEvent/userRecordScoreV2")
                || uri.startsWith("/api/stadium/gameEvent/updateOpponentV2")) {
            emails = "lei.w@quncaotech.com";
        }else if (uri.startsWith("/api/datesport")) {
            emails = "ke.zheng@quncaotech.com";
        }else {
            emails = "dongsheng.lin@quncaotech.com";
        }
        EmailUtils.getInstance().sendHtmlEmails(emails, "[服务器]:"+request.getServerName()+EMAIL_SUBJECT+request.getRequestURI(), errorMsg);
    }
}
